<%@ page import="de.home.db.DBService"%>
<%@ page import="de.home.db.model.Floor"%>
<%@ page import="de.home.db.model.Room"%>
<%@ page import="de.home.db.model.RemotePowerPoint"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*"%>
<!DOCTYPE>
<html>
<head>
<title>Home Controller</title>
<link rel="stylesheet" type="text/css" href="css/generalStyle.css">
<link rel="stylesheet" type="text/css" href="css/styleController.css">
<script src="js/jquery-2.1.1.js"></script>
<!--script src="js/jquery.mobile-1.4.5.min.js" type="text/javascript"></script-->
<script src="js/scriptController.js" type="text/javascript"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js" type="text/javascript"></script>
<script src="js/generalScript.js" type="text/javascript"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<meta name="mobile-web-app-capable" content="yes">
</head>
<body>
	<div id="title">
		<div>
			<a id="top" href="index.jsp"></a>
			<a id="normal"></a>
			<h1>Home Controller</h1>
		</div>
	</div>
	<div id="errorBox"></div>
	<div id="infoBox"></div>
	<div id="warningBox"></div>

	<%
	   DBService dbService = DBService.getInstance();
	   List<Floor> floors = dbService.getFloorsWithoutRooms();
	   if ( floors.isEmpty() ) {
	%>
	<div id="warningBox">KEINE Eintr&auml;ge gefunden!</div>
	<%
	   } else {
	      String selectedFloorStringId = request.getParameter("selectedFloorId");
	      Floor selectedFloor = floors.get(0);
	      if(selectedFloorStringId != null){
	         int id = Integer.parseInt(selectedFloorStringId);
	         boolean found = false;
	         for (int i = 0; i < floors.size(); i++) {
		         if(floors.get(i).getId() == id){
		            selectedFloor = floors.get(i);
		            floors.remove(i);
		            found = true;
		         }
	            	
	         }
	         if(!found)
	        	 floors.remove(0);
	      }else{
	    	  floors.remove(0);
	      }
	      
	%>

	<header>
		<ul id="floorChoice">
			<%if(floors.size() > 0){ %>
			<li data-floorId="<%=selectedFloor.getId()%>"><a><%=selectedFloor.getName()%></a>
				<div id="dropDownArrow"></div>
				<div id="dropDownArrow2"></div>
			</li>
			<ul>
				<%
				   for (int i = 0; i < floors.size(); i++) {
				%>
				<li class="floorSelect" data-floorId="<%=floors.get(i).getId()%>"><a><%=floors.get(i).getName()%></a></li>
				<%
				   }
				%>

			</ul>
			<% }
				else{%>
				<li data-floorId="<%=selectedFloor.getId()%>"><a style="cursor: default;"><%=selectedFloor.getName()%></a>
				</li>
			 <%}%>	
		</ul>
	</header>
	
	 <%
      List<Room> rooms = dbService.getRooms(selectedFloor.getId());
      if(rooms.isEmpty()){
      %>
      	 <div id="warningBox">KEINE Zimmer gefunden!</div>
         <!--h1 id="noEntry">KEINE Zimmer gefunden!</h1-->
      <%
      }
      else {
      %>
      <ul class="rooms">
           <% for(Room r : rooms) { %>
           
            <li class="room">
               <div class="roomTitle">
               <div></div>
               <h1><%=r.getName() %></h1>
               </div>
               <!--h1 class="deviceNameLabel">Ger&auml;te Name</h1-->
                     
                  <% 
                  for(RemotePowerPoint rpp : r.getRemotePowerPoints()) {
                  %>
                  <div class="remote" data-fId="<%= rpp.getId() %>">
                     <div class="nameLabel"><h1><%= rpp.getGeraetename() %></h1></div>
                     <div class="onOffPanel">
	                     <div class="on"><img src="pic/on.png"></img></div>
    	                 <div class="off"><img src="pic/on.png"></img></div>
                     </div>
                  </div>   
                 
                  <% } %>
                  
            </li>
            <% } %>
         </ul>
      <% } %>

	<%
	   }
	%>
</body>
</html>